<?php
/**
 * Created by PhpStorm.
 * User: minicart
 * Date: 2018/9/22
 * Time: 11:07
 */

namespace app\models;

use think\Model;

/**
 * Class GoodsWaitModel
 * @package app\models
 */
class GoodsWaitModel extends Model
{
    protected $table = 'edu_goods_wait';

    /**
     * 订单列表 分页
     * @param array $where
     * @param int $page
     * @param int $limit
     * @param string $order
     * @param string $time
     * @return array
     * @throws \think\exception\DbException
     */
    public static function pageLists($where = [], $page = 1, $limit = 5, $order = 'id desc', $time = '')
    {
        if($time){
            $result = self::where($where)->whereTime('register_time',$time)->order($order)->paginate($limit, false, ['page' => $page]);
        }else{
            $result = self::where($where)->order($order)->paginate($limit, false, ['page' => $page]);
        }
        if (!$result->total()) {
            return ['code' => 0, 'msg' => "ok", 'count' => 0, 'data' => []];
        }
        $goodsModel = new GoodsModel();
        foreach ($result as $value) {
            $value['name'] = $goodsModel->where('id', $value['gid'])->value('name');
        }
        $result = $result->toArray();
        return ['code' => 0, 'msg' => "ok", 'count' => $result['total'], 'data' => $result['data']];
    }
}